define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'shop.store/index',
        add_url: 'shop.store/add',
        edit_url: 'shop.store/edit',
        delete_url: 'shop.store/delete',
        export_url: 'shop.store/jsExport',
        modify_url: 'shop.store/modify',
        create_qrcode: 'shop.store/createQrcode',
        export_qrcode: 'shop.store/exportQrcode',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh', 'add', 'delete', 'export',[ {
                        class : 'layui-btn layui-btn-sm layui-btn-warning',
                        icon : 'fa fa-bookmark',
                        auth : '',
                        url : init.export_qrcode,
                        method : 'open',
                        title : '导出二维码',
                        text : '导出二维码',
                }]],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'id', width: 80},
                    {field: 'cate.title', title: '店铺类型', width: 100},
                    {field: 'title', title: '店铺名称', minWidth: 150, edit: 'text'},
                    {field: 'qrcode', minWidth: 50, title: '支付二维码', search: false, templet: ea.table.image},
                    // {field: 'merchant_id', title: '商户号'},
                    // {field: 'bind_user_wechat', title: '绑定微信'},
                    // {field: 'bind_user_alipay', title: '绑定支付宝'},
                    {field: 'brief', title: '简介', edit: 'text', minWidth: 200, search: false},
                    // {field: 'album', title: '店铺图集'},
                    {field: 'shop_cover', title: '店铺封面', templet: ea.table.image, search: false},
                    {field: 'address', title: '店铺地址'},
                    {field: 'status', title: '店铺状态', width: 90, selectList: {0: '关', 1: '开'}, templet: ea.table.switch},
                    {field: 'shop_sort', title: '店铺排序', width: 90, edit: 'text'},
                    // {field: 'lng', title: '经度'},
                    // {field: 'lat', title: '纬度'},
                    {
                        width: 250, title: '操作', templet: ea.table.tool,
                        operate: ['edit',
                            [
                                {
                                    method: 'get',
                                    field: 'id',
                                    title: '确定删除店铺？',
                                    // icon: 'fa fa-close',
                                    text: '删除',
                                    url: init.delete_url,
                                    auth: 'delete',
                                    class: 'layui-btn layui-btn-danger layui-btn-xs',
                                    br: true,
                                },
                                {
                                    text: '支付二维码',
                                    url: init.create_qrcode,
                                    icon: 'fa fa-refresh',
                                    method: 'request',
                                    auth: 'createQrcode',
                                    class: 'layui-btn layui-btn-normal layui-btn-xs',
                                }
                            ]
                        ]
                    },

                ]],
            });

            ea.listen();
        },
        add: function () {
            //加载时间控件
            layui.laydate.render({
                elem: '#start_at', //指定元素
                type: 'time',
                format: 'HH:mm',
            });
            layui.laydate.render({
                elem: '#end_at', //指定元素
                type: 'time',
                format: 'HH:mm',
            });
            ea.listen();
        },
        edit: function () {
            //加载时间控件
            layui.laydate.render({
                elem: '#start_at', //指定元素
                type: 'time',
                format: 'HH:mm',
            });
            layui.laydate.render({
                elem: '#end_at', //指定元素
                type: 'time',
                format: 'HH:mm',
            });
            ea.listen();
        },
    };
    return Controller;
});